package com.njwb.day12.fanshe;

import java.lang.reflect.Method;

public class ReflectTest {
    public static void main(String[] args) throws Exception {

        Class clazz = MyMath.class;

        Method add=clazz.getDeclaredMethod("add",int.class,int.class);
        add.setAccessible(true);
        Object result1=add.invoke(null,5,7);
        System.out.println("add(5, 7) = " + result1);


        Method isOddMethod = clazz.getMethod("isOdd", int.class);
        Object result2 = isOddMethod.invoke(null, 9);
        System.out.println("isOdd(9) = " + result2);

        Object myMathObj = clazz.getDeclaredConstructor().newInstance(); // 创建实例
        Method setValueMethod = clazz.getMethod("setValue", String.class);
        setValueMethod.invoke(myMathObj, "Hello Reflection!");


    }
}
